﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;

namespace OestsServer.Handlers.OESPHandlers
{

    public class SetTaskTimeHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.SetTaskTime;

        public override void Execute(OESPClientChannel client, Request packet)
        {
            base.Execute(client, packet);

            DP<int, int, int> data = JsonMapper.ToObject<DP<int, int, int>>(packet.DataStr);
            if (TaskDAL.SetTaskTime(data.Value1, data.Value2, data.Value3))
            {
                ResponsePacket.ReturnCode = ReturnCode.Success;
                ResponsePacket.DataObject = data;
            }
            else
            {
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "设置所有任务时间失败！";
            }
            client.Send(ResponsePacket);
        }
    }


    public class SetAllTaskDefaultTimeHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.SetAllTaskDefaultTime;
        public override void Execute(OESPClientChannel client, Request packet)
        {
            base.Execute(client, packet);

            int projectid = int.Parse(packet.DataStr);
            if (TaskDAL.SetAllTaskDefaultTime(projectid))
            {
                ResponsePacket.DataObject = projectid;
                ResponsePacket.ReturnCode = ReturnCode.Success;
            }
            else
            {
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "设置所有任务默认时间失败！";
            }
            client.Send(ResponsePacket);
        }
    }

    public class ResetTaskDefaultTimeHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.ResetTaskDefaultTime;

        public override void Execute(OESPClientChannel client, Request packet)
        {
            base.Execute(client, packet);


            DP<int, int, int> data = JsonMapper.ToObject<DP<int, int, int>>(packet.DataStr);
            if (TaskDAL.ResetTaskDefaultTime(data.Value1, data.Value2, data.Value3))
            {
                ResponsePacket.ReturnCode = ReturnCode.Success;
                ResponsePacket.DataObject = data;
            }
            else
            {
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "重设默认时间失败！";
            }
            client.Send(ResponsePacket);
        }
    }


}